package com.tan.kotlintest.activity

import android.content.Intent
import android.view.View
import android.widget.AdapterView
import com.tan.kotlintest.R
import com.tan.kotlintest.adapter.MainListAdapter
import com.tan.kotlintest.annotation.TestAnnotationActivity
import com.tan.kotlintest.autosizetextview.TestTextViewAutoSizeActivity
import com.tan.kotlintest.base.AppManager
import com.tan.kotlintest.base.BaseActivity
import com.tan.kotlintest.changeskin.TestSkinMainActivity
import com.tan.kotlintest.constraint.TestConstraintOneActivity
import com.tan.kotlintest.countdownlatch.TestCountDownLatchActivity
import com.tan.kotlintest.dispatchevent.TestDispatchEventActivity
import com.tan.kotlintest.eventpass.TestEventPassActivity
import com.tan.kotlintest.guonet.TestGuoNetActivity
import com.tan.kotlintest.hotfix.classloader.TestClassLoaderActivity
import com.tan.kotlintest.hotfix.multidex.TestMultiDexActivity
import com.tan.kotlintest.leo_daemon.TestDaemonMainActivity
import com.tan.kotlintest.net.TestNetActivity
import com.tan.kotlintest.palette.TestPaletteActivity
import com.tan.kotlintest.pictureload.TestPictureLoadActivity
import com.tan.kotlintest.recycler.TestListViewActivity
import com.tan.kotlintest.recycler.TestRecyclerViewActivity
import com.tan.kotlintest.retrofit.TestRetrofitActivity
import com.tan.kotlintest.rxjava.rxjavamerga.TestRxJavaMergaActivity
import com.tan.kotlintest.shareelement.TestShareElementActivity
import com.tan.kotlintest.snaphelper.TestSnapHelperActivity
import com.tan.kotlintest.static.TestObject
import com.tan.kotlintest.trace.TestTraceViewActivity
import com.tan.kotlintest.view.TestCustomViewActivity
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.base_app_head.*


/*
 * Copyright (C) 2018 重庆一聊高科技有限公司
 * 版权所有
 *
 * 功能描述：测试Kotlin工程  主页面
 * 作者：txj
 * 创建时间：2018/9/5
 *
 * 修改人：
 * 修改描述：
 * 修改日期
 */
class MainActivity : BaseActivity(), AdapterView.OnItemClickListener {

    override fun getContentView(): View {
        return inflate(R.layout.activity_main)
    }

    override fun onContentAdded() {
        setTitleText(R.string.main_title)
        initListView()
        AppManager.instance?.isMainPageShareQun = true
        //LogUtil.i("测试AppManager单例写法: " + AppManager.instance?.isMainPageShareQun)

        //val test2 = TestObject
        //test2.name = "22222222"
        //LogUtil.i("测试Object对象声明: test1.name = ${test1.name} test2.name = ${test2.name}")
        //Kotlin中位运算

        val test1 = TestObject
        test1.name = "1111"
        test1.let {
            it.name = "33333"
        }
        test1.run {
            name = "5555555555"
        }
    }

    /**
     * 初始化ListView
     */
    private fun initListView() {
        left_fl.visibility = View.GONE
        left_fl.invalidate()
        //获取数据
        val mainArray = resources.getStringArray(R.array.main_list)
        val mainListAdapter = MainListAdapter(this)
        mainListAdapter.loadData(mainArray)
        content_lv.adapter = mainListAdapter
        content_lv.onItemClickListener = this
    }

    override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
        when (position) {
            0 -> {//测试页面
                startActivity(Intent(applicationContext, TestActivity::class.java))
            }
            1 -> {//测试点击事件的写法
                startActivity(Intent(applicationContext, TestClickListenerActivity::class.java))
            }
            2 -> {//测试Kotlin中的空安全
                startActivity(Intent(applicationContext, TestNullActivity::class.java))
            }
            3 -> {
                startActivity(Intent(applicationContext, TestSmallestWidthActivity::class.java))
            }
            4 -> {//测试activity的隐式调用
                val intent = Intent()
                intent.action = "haha"
                intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
                intent.addCategory("haha")
                startActivity(intent)
            }
            5 -> {//测试炫酷的过场动画 ShareElement
                val intent = Intent(applicationContext, TestShareElementActivity::class.java)
                startActivity(intent)
            }
            6 -> {//测试android自带侧滑栏
                startActivity(Intent(applicationContext, TestDrawerLayoutActivity::class.java))
            }
            7 -> {//测试DBlur 高斯模糊
                startActivity(Intent(applicationContext, TestDBlurActivity::class.java))
            }
            8 -> {//测试RecyclerView 的SnapHelper实现ViewPager等效果
                startActivity(Intent(applicationContext, TestSnapHelperActivity::class.java))
            }
            9 -> {//测试Level-List drawable
                startActivity(Intent(applicationContext, TestLevelListDrawableActivity::class.java))
            }
            10 -> {//测试图片三级缓存
                startActivity(Intent(applicationContext, TestPictureLoadActivity::class.java))
            }
            11 -> {//测试RecyclerView加载大量数据
                startActivity(Intent(applicationContext, TestRecyclerViewActivity::class.java))
            }
            12 -> {//测试ListView加载大量数据
                startActivity(Intent(applicationContext, TestListViewActivity::class.java))
            }
            13 -> {//测试Android事件传递机制
                startActivity(Intent(applicationContext, TestEventPassActivity::class.java))
            }
            14 -> {//测试android TraceView检查方法耗时
                startActivity(Intent(applicationContext, TestTraceViewActivity::class.java))
            }
            15 -> {//测试郭神网络请求框架
                startActivity(Intent(applicationContext, TestGuoNetActivity::class.java))
            }
            16 -> {
                startActivity(Intent(applicationContext, TestCountDownLatchActivity::class.java))
            }
            17 -> {//RXJava+Retrofit的结合使用，来同时请求多个网络接口,然后刷新页面
                startActivity(Intent(applicationContext, TestRxJavaMergaActivity::class.java))
            }
            18 -> {//测试Palette调色板,获取Bitmap中的活跃颜色,其他控件可以设置该颜色,来让界面更加协调
                startActivity(Intent(applicationContext, TestPaletteActivity::class.java))
            }
            19 -> {//测试TextView自动改变字体大小 autoSize***属性
                startActivity(Intent(applicationContext, TestTextViewAutoSizeActivity::class.java))
            }
            20 -> {//测试Retrofit网络请求框架
                startActivity(Intent(applicationContext, TestRetrofitActivity::class.java))
            }
            21 -> {//测试自定义View
                startActivity(Intent(applicationContext, TestCustomViewActivity::class.java))
            }
            22 -> {//测试ConstraintLayout约束布局
                startActivity(Intent(applicationContext, TestConstraintOneActivity::class.java))
            }
            23 -> {//测试HttpUrlConnection网络请求
                startActivity(Intent(applicationContext, TestNetActivity::class.java))
            }
            24 -> {//测试注解反射
                startActivity(Intent(applicationContext, TestAnnotationActivity::class.java))
            }
            25 -> {//测试换肤
                startActivity(Intent(applicationContext, TestSkinMainActivity::class.java))
            }
            26 -> {//测试multidex热修复
                startActivity(Intent(applicationContext, TestMultiDexActivity::class.java))
            }
            27 -> {//测试ClassLoader类加载器
                startActivity(Intent(applicationContext, TestClassLoaderActivity::class.java))
            }
            28 -> {//测试事件分发
                startActivity(Intent(applicationContext, TestDispatchEventActivity::class.java))
            }
            29 -> {//测试
                startActivity(Intent(applicationContext, TestDaemonMainActivity::class.java))
            }
            30 -> {//测试发送全局广播
                startActivity(Intent(applicationContext, TestSendWholeBroadcastActivity::class.java))
            }
        }
    }

}
